-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add databricks_function
resource
#4189
base: main
Are you sure you want to change the base?
Conversation
…source updating feature branch.
databricks_function
resourcedatabricks_function
resource
databricks_function
resourcedatabricks_function
resource
Hello, is there any timeline on when this could make it into the provider? Would love to have this soon! |
Hi @ian-norris-ncino. I'm aiming to have this integrated into the provider by the end of the month, depending on my availability. I'll keep you posted. |
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
databricks_function
resourcedatabricks_function
resource
name = "calculate_bmi" | ||
catalog_name = databricks_catalog.sandbox.name | ||
schema_name = databricks_schema.functions.name | ||
input_params = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be easier for people to specify input_param
as separate blocks, like we do in other resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although doc says that input_params
is a block, and then there are parameters inside: https://docs.databricks.com/api/workspace/functions/create#input_params
* `name` - (Required) The name of the parameter. | ||
* `type` - (Required) The data type of the parameter (e.g., `DOUBLE`, `INT`, etc.). | ||
* `data_type` - (Required) The return data type of the function (e.g., `DOUBLE`). | ||
* `routine_body` - (Required) Specifies the body type of the function, either `SQL` for SQL-based functions or `EXTERNAL` for functions in external languages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see return_params
Test Details: go/deco-tests/11869831592 |
func waitForFunction(ctx context.Context, w *databricks.WorkspaceClient, funcInfo *catalog.FunctionInfo) diag.Diagnostics { | ||
const timeout = 5 * time.Minute | ||
|
||
result, err := retries.Poll[catalog.FunctionInfo](ctx, timeout, func() (*catalog.FunctionInfo, *retries.Err) { | ||
attempt, err := w.Functions.GetByName(ctx, funcInfo.FullName) | ||
if err != nil { | ||
if apierr.IsMissing(err) { | ||
return nil, retries.Continue(fmt.Errorf("function %s is not yet available", funcInfo.FullName)) | ||
} | ||
return nil, retries.Halt(fmt.Errorf("failed to get function: %s", err)) | ||
} | ||
return attempt, nil | ||
}) | ||
|
||
if err != nil { | ||
return diag.Diagnostics{diag.NewErrorDiagnostic("failed to create function", err.Error())} | ||
} | ||
|
||
*funcInfo = *result | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need it for functions? I thought that function creation should be fast.
c.SetRequired("data_type") | ||
c.SetRequired("routine_body") | ||
c.SetRequired("routine_defintion") | ||
c.SetRequired("language") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full_data_type
marked as required
in API spec: https://docs.databricks.com/api/workspace/functions/create but I'm not sure if it's really required. We need to check with UC team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly for is_null_call and is_deterministic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dgomez04, thanks for the PR, left some comments.
} | ||
|
||
func waitForFunction(ctx context.Context, w *databricks.WorkspaceClient, funcInfo *catalog.FunctionInfo) diag.Diagnostics { | ||
const timeout = 5 * time.Minute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the 5minute timeout expected for function? Just wanted to check if this should be bigger or smaller?
|
||
funcInfo, err := w.Functions.Create(ctx, createReq) | ||
if err != nil { | ||
resp.Diagnostics.AddError("failed to create function", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should return after this
return | ||
} | ||
|
||
funcInfo, err := w.Functions.Update(ctx, updateReq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is waiting only required during creation? or also during update?
|
||
funcInfo, err := w.Functions.Update(ctx, updateReq) | ||
if err != nil { | ||
resp.Diagnostics.AddError("failed to update function", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here -- we should return after this
} | ||
|
||
func TestFunctionResource(t *testing.T) { | ||
acceptance.UnityWorkspaceLevel(t, acceptance.Step{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add another step to test the update pathway.
Changes
Introduces
databricks_function
resource—allowing users to create and manage UDFs within Terraform. work in progress...Closes #4074
Tests
make test
run locallydocs/
folderinternal/acceptance